% fname: routing_oddeven__sel_random__topology_8x8__.m
% ./noxim -routing oddeven -sel random -dimx 8 -dimy 8  -sim 10000 -warmup 2000 -size 8 8 -buffer 4 -hs 27 0.2 -hs 28 0.2 -hs 35 0.2 -hs 36 0.2 

function [max_pir, max_throughput, min_delay] = routing_oddeven__sel_random__topology_8x8__(symbol)

data = [
%             pir      avg_delay     throughput      max_delay       rpackets         rflits
            0.002        18.1761      0.0165685            125           1028           8218
            0.002        18.4265      0.0163294            127           1027           8230
            0.002        16.7637      0.0167964             85           1041           8331
            0.002        16.9646      0.0157664             80            961           7694
            0.002        17.6391      0.0160081            103            992           7940
            0.002        19.4016      0.0160575            144           1011           8093
            0.002        17.8751      0.0167718            122           1057           8453
            0.002        18.9732      0.0169277            163           1084           8667
            0.002        18.8745      0.0160595            182           1012           8094
            0.002        17.8217      0.0170146             89           1021           8167
            0.002        18.7083      0.0169127            227           1066           8524
            0.002        18.6561      0.0175266            119           1070           8553
            0.002        18.2043       0.016125            112           1033           8256
            0.002        19.2471      0.0167459            216           1024           8172
            0.002        18.7376      0.0173448            107           1006           8048
            0.002        17.7285      0.0152539            135            976           7810
            0.002        19.8598      0.0171825            132           1084           8660
            0.002        17.2795      0.0171062             79           1027           8211
            0.002        21.8005      0.0184792            194           1108           8870
            0.002        18.8175      0.0177705            111           1085           8672
           0.0022        17.4466      0.0172157             90           1068           8539
           0.0022        20.3003      0.0176865            148           1079           8631
           0.0022        20.8861      0.0172976            212           1089           8718
           0.0022        18.3677      0.0183214            111           1153           9234
           0.0022        19.1074      0.0178238            155           1089           8698
           0.0022        19.0992      0.0175853            121           1109           8863
           0.0022        19.1777      0.0174841            143           1103           8812
           0.0022        20.0966      0.0181328            257           1160           9284
           0.0022        19.5746      0.0174531            110           1119           8936
           0.0022         20.282       0.017873            181           1124           9008
           0.0022        21.0418      0.0192581            142           1195           9552
           0.0022        18.4246      0.0179637             88           1114           8910
           0.0022         21.206      0.0191475            210           1170           9344
           0.0022        21.7011      0.0192016            251           1191           9524
           0.0022        20.0689      0.0174512            172           1117           8935
           0.0022        21.9818      0.0183552            449           1156           9251
           0.0022        20.4682      0.0175159            197           1102           8828
           0.0022        19.0881      0.0172031            102           1101           8808
           0.0022        19.2043      0.0175117            145           1121           8966
           0.0022        19.9904      0.0181667            148           1144           9156
           0.0024        22.0957      0.0205533            154           1254          10030
           0.0024        21.9797       0.020209            149           1232           9862
           0.0024        21.9306      0.0185968            157           1153           9224
           0.0024        22.8716      0.0199262            152           1215           9724
           0.0024          21.81      0.0191582            146           1226           9809
           0.0024        22.5891      0.0193869            217           1224           9771
           0.0024        20.4854      0.0190337            131           1199           9593
           0.0024        20.2941      0.0185625            114           1190           9504
           0.0024        20.8672      0.0181406            167           1160           9288
           0.0024        24.3244      0.0202582            271           1236           9886
           0.0024        22.4739       0.019504            259           1228           9830
           0.0024        21.6812      0.0195766            154           1214           9710
           0.0024        21.1726      0.0200907            185           1246           9965
           0.0024        24.0432      0.0211758            241           1249           9995
           0.0024        21.4769      0.0192871            127           1235           9875
           0.0024        22.3516      0.0194375            256           1243           9952
           0.0024        20.1718        0.01925            161           1193           9548
           0.0024        20.1078      0.0188652            129           1206           9659
           0.0024        21.7004      0.0200685            178           1245           9954
           0.0024        25.8545      0.0200762            297           1285          10279
           0.0026        23.2165      0.0204798            209           1270          10158
           0.0026        26.5633      0.0209707            268           1342          10737
           0.0026        21.5627       0.021125            155           1308          10478
           0.0026        27.5338      0.0210176            238           1345          10761
           0.0026        25.4521      0.0212083            242           1336          10689
           0.0026         27.536       0.021293            271           1362          10902
           0.0026        25.6871      0.0208711            139           1336          10686
           0.0026        23.8208      0.0215254            205           1378          11021
           0.0026        29.5488      0.0211687            302           1332          10669
           0.0026        27.9364      0.0210464            413           1305          10439
           0.0026        26.4304      0.0216504            208           1387          11085
           0.0026        24.4633      0.0206426            167           1321          10569
           0.0026        25.1861      0.0209043            163           1338          10703
           0.0026        26.0902      0.0207937            264           1308          10480
           0.0026        24.0071      0.0219219            196           1404          11224
           0.0026        27.4232      0.0217664            453           1328          10622
           0.0026        28.9272        0.02125            267           1360          10880
           0.0026        25.4869      0.0206071            298           1300          10386
           0.0026        26.8066      0.0218448            201           1355          10835
           0.0026        24.1894       0.021631            197           1362          10902
           0.0028         30.038      0.0230195            302           1474          11786
           0.0028        29.6794       0.022373            314           1410          11276
           0.0028        23.3326      0.0210391            158           1347          10772
           0.0028        26.4784      0.0220258            199           1388          11101
           0.0028        27.4241       0.022121            205           1396          11149
           0.0028        26.3033      0.0225273            155           1441          11534
           0.0028        33.7116      0.0229464            539           1446          11565
           0.0028        30.8296      0.0224609            335           1438          11500
           0.0028        28.4436      0.0220059            214           1409          11267
           0.0028        30.3196      0.0224492            277           1436          11494
           0.0028        27.4267      0.0219551            160           1406          11241
           0.0028        35.9545      0.0236944            457           1493          11942
           0.0028        27.8521      0.0231111            208           1454          11648
           0.0028        30.4348      0.0229167            329           1442          11550
           0.0028        32.2345      0.0228214            312           1437          11502
           0.0028        28.4048      0.0221445            323           1418          11338
           0.0028        25.2979      0.0219258            211           1403          11226
           0.0028        28.7658      0.0220137            216           1409          11271
           0.0028        28.7078      0.0227734            202           1458          11660
           0.0028        30.3804      0.0228648            322           1396          11158
            0.003         36.853      0.0248652            383           1592          12731
            0.003        36.2726      0.0245655            413           1548          12381
            0.003        37.2474      0.0229492            713           1467          11750
            0.003        31.5691      0.0229395            413           1469          11745
            0.003        47.1687      0.0241367            487           1547          12358
            0.003        27.7408      0.0225234            211           1443          11532
            0.003         33.417      0.0240833            360           1518          12138
            0.003        30.3992      0.0239375            254           1533          12256
            0.003        38.2794      0.0239199            646           1532          12247
            0.003        33.2748      0.0241152            347           1543          12347
            0.003        37.8485      0.0233145            439           1492          11937
            0.003        38.7989      0.0246348            483           1576          12613
            0.003         32.921      0.0251066            544           1532          12252
            0.003        30.2873      0.0239648            310           1535          12270
            0.003         30.913      0.0235218            314           1483          11855
            0.003        41.1958      0.0242656            633           1553          12424
            0.003        39.5238      0.0240397            595           1514          12116
            0.003        33.2945      0.0242969            260           1555          12440
            0.003        36.1756      0.0241211            459           1543          12350
            0.003        34.7601      0.0240898            336           1542          12334
           0.0032        36.3282      0.0242969            418           1554          12440
           0.0032        43.1627      0.0246602            377           1580          12626
           0.0032        39.5604      0.0253851            536           1574          12591
           0.0032        60.1871      0.0266548            908           1678          13434
           0.0032        39.1804      0.0246934            365           1580          12643
           0.0032        40.3113      0.0264727            365           1696          13554
           0.0032        34.8799      0.0258849            345           1632          13046
           0.0032        42.5957      0.0256973            699           1645          13157
           0.0032        46.3253      0.0259336            552           1660          13278
           0.0032        47.3094      0.0263691            760           1687          13501
           0.0032        46.7712      0.0262266            591           1678          13428
           0.0032        58.4033      0.0263223            997           1686          13477
           0.0032         47.708      0.0257004            654           1620          12953
           0.0032        79.8575       0.027293           1538           1747          13974
           0.0032        44.1762      0.0259687            721           1663          13296
           0.0032        49.5835      0.0267083            638           1683          13461
           0.0032         85.796      0.0260469           1552           1667          13336
           0.0032        63.7546      0.0265139            802           1671          13363
           0.0032        72.9862      0.0264702           1522           1667          13341
           0.0032        51.1081      0.0251289            542           1609          12866
           0.0034        47.0046       0.027418            820           1756          14038
           0.0034        111.694      0.0280039           1439           1791          14338
           0.0034        49.2345      0.0269286            749           1697          13572
           0.0034        51.9348      0.0279782            656           1763          14101
           0.0034        137.459      0.0276016           2759           1766          14132
           0.0034        62.5859      0.0273945            499           1753          14026
           0.0034        58.1702      0.0269785            731           1727          13813
           0.0034        120.159      0.0279861           1886           1762          14105
           0.0034        73.3568      0.0266309           1870           1704          13635
           0.0034        87.6538      0.0278512            952           1756          14037
           0.0034        60.2133      0.0265723            665           1702          13605
           0.0034        87.9816      0.0272324           2152           1742          13943
           0.0034        111.792      0.0288095           1773           1816          14520
           0.0034        51.9136      0.0262698            576           1655          13240
           0.0034         51.954      0.0272937            607           1719          13756
           0.0034        88.6264      0.0284727           1014           1823          14578
           0.0034         51.126      0.0275202            720           1706          13650
           0.0034        68.6665      0.0271349            857           1709          13676
           0.0034        71.4075      0.0272148           1050           1740          13934
           0.0034        72.6312       0.027623           1010           1768          14143
           0.0036        213.021      0.0298223           2678           1908          15269
           0.0036        69.1046      0.0282246            784           1807          14451
           0.0036        118.627      0.0281706           1902           1774          14198
           0.0036         104.04      0.0289199           1147           1851          14807
           0.0036        199.108      0.0287637           3040           1839          14727
           0.0036        130.537      0.0290879           1666           1862          14893
           0.0036        123.442      0.0284648           1776           1822          14574
           0.0036        66.4721      0.0277051            753           1773          14185
           0.0036        185.733      0.0279961           2810           1793          14334
           0.0036        147.127      0.0291448           2040           1836          14689
           0.0036         78.188      0.0284199           1332           1819          14551
           0.0036        134.103      0.0286074           1846           1830          14647
           0.0036        82.3419      0.0281172            834           1799          14396
           0.0036        433.769      0.0288672           3896           1849          14780
           0.0036        65.6462      0.0280078            988           1792          14340
           0.0036        63.2449      0.0270625            896           1731          13856
           0.0036        152.377      0.0287441           1778           1839          14717
           0.0036        260.982       0.028918           3276           1851          14806
           0.0036         87.299      0.0276543            977           1769          14159
           0.0036        111.637      0.0288398           1152           1844          14766
           0.0038        164.467      0.0296992           2007           1899          15206
           0.0038        121.762      0.0306504           1328           1962          15693
           0.0038        418.406      0.0304863           6442           1952          15609
           0.0038        242.774      0.0295918           3235           1895          15151
           0.0038        312.508      0.0287837           3353           1815          14507
           0.0038        162.819      0.0294663           1416           1855          14851
           0.0038         226.17      0.0299609           2070           1918          15340
           0.0038        438.329      0.0308984           5375           1979          15820
           0.0038        172.336      0.0287637           2581           1841          14727
           0.0038         190.91      0.0299082           3584           1912          15313
           0.0038        236.566      0.0286523           2463           1833          14670
           0.0038        213.074      0.0299414           2352           1917          15330
           0.0038        146.248      0.0299219           1888           1916          15320
           0.0038         175.82      0.0294414           2232           1883          15074
           0.0038        159.551      0.0299316           1724           1919          15325
           0.0038        185.609      0.0301211           2399           1928          15422
           0.0038        187.242      0.0299082           1834           1914          15313
           0.0038        348.551      0.0279238           5169           1787          14297
           0.0038        207.538      0.0302656           2610           1938          15496
           0.0038        247.091      0.0297383           3276           1903          15226
];

rows = size(data, 1);
cols = size(data, 2);

data_delay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+1);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_delay = [data_delay; data(ifirst, 1:cols-5), avg ci];
end

figure(1);
hold on;
plot(data_delay(:,1), data_delay(:,2), symbol);

data_throughput = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+2);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_throughput = [data_throughput; data(ifirst, 1:cols-5), avg ci];
end

figure(2);
hold on;
plot(data_throughput(:,1), data_throughput(:,2), symbol);

data_maxdelay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+3);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_maxdelay = [data_maxdelay; data(ifirst, 1:cols-5), avg ci];
end

figure(3);
hold on;
plot(data_maxdelay(:,1), data_maxdelay(:,2), symbol);


%-------- Saturation Analysis -----------
slope=[];
for i=2:size(data_throughput,1),
    slope(i-1) = (data_throughput(i,2)-data_throughput(i-1,2))/(data_throughput(i,1)-data_throughput(i-1,1));
end

for i=2:size(slope,2),
    if slope(i) < (0.95*mean(slope(1:i)))
        max_pir = data_throughput(i, 1);
        max_throughput = data_throughput(i, 2);
        min_delay = data_delay(i, 2);
        break;
    end
end
